/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ec.socialfun.util;

import com.google.gson.Gson;
import java.util.List;
import org.jboss.logging.Logger;

/**
 *
 * @author jorge
 */
public class JsonUtil {

    private static final Logger LOG = Logger.getLogger(JsonUtil.class.getName());

    /**
     * tranforma una lista de objetos en una cadena json valida
     * @param lista
     * @return
     */
    public static String listaAJson(List<SelectOption> lista) {
        Gson gson = new Gson();
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        int band = 0;
        for (SelectOption obj : lista) {
            String json = gson.toJson(obj);
            if (band > 0) {
                sb.append(",");
            }
            sb.append(json);
            band = 1;
        }
        sb.append("]");

        LOG.info(" JSON Creado:  " + sb.toString());
        return sb.toString();

    }
}
